#!/usr/bin/env python3
import argparse, sys

from strange_io.text import StrangeText

parser = argparse.ArgumentParser()
parser.add_argument('file_path', nargs='?')
parser.add_argument('-i', help='Simply converts a plain text document to a strange text document')
parser.add_argument('-e', help='Simply converts a strange text document to a plain text document')
args = parser.parse_args()

if __name__ == '__main__':
    document = StrangeText()
    if args.i:
        if not args.file_path:
            sys.exit("No output path")
        with open(args.i) as f:
            inp = f.read()
            f.close()
        document.load(inp)
        document.dump_file(args.file_path)
    elif args.e:
        if not args.file_path:
            sys.exit("No input path")
        document.load_file(args.file_path)
        inp = document.dump()
        with open(args.e, 'w') as f:
            f.write(inp)
            f.close()
    else:
        del document
        import gui
        gui.main(args)
